//
//  Unit.m
//  DIsciplineSelectPartner
//
//  Created by 唐秦崴 on 15/3/16.
//  Copyright (c) 2015年 Lizzy. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <BmobSDK/Bmob.h>
#import "Unit.h"


@implementation Unit

@synthesize objectId = _objectId;
@synthesize name = _name;
@synthesize subject = _subject;
@synthesize university = _university;
@synthesize major = _major;

- (instancetype)initWithBmobObject : (BmobObject*) bmobObject
{
    self = [super init];
    
    if (bmobObject) {
        self.objectId   = bmobObject.objectId;
        self.name       = [bmobObject objectForKey:@"name"];
        self.subject    = [bmobObject objectForKey:@"subject"];  // 数组能直接赋值
        self.university = [bmobObject objectForKey:@"university"];
        self.major      = [bmobObject objectForKey:@"major"];

    }
    
    return self;
    
}

// 将选科要求转换成字符串输出
- (NSString*) subjectToString
{
    NSString* str = @"";
    if( _subject ){
        if ([ _subject count ]) {
            for ( int i = 0; i < _subject.count; i++ ) {
                str = [ str stringByAppendingString: [ _subject objectAtIndex:i ] ];
                // 为最后一个元素之前的元素增加间隔符
                if ( _subject.count - 1 > i ) {
                    str = [ str stringByAppendingString: @"," ];
                };
                
            }
            
        }
    }
    return str;
}

// 将major字符串类型转换为数组
-(NSArray*) majorsArray
{
    if ( _major.length ) {
        
        NSArray* array = [ _major componentsSeparatedByString:@"," ];
        return array;
    }
    else{
        return nil;
    }
}

@end